#include <cmath>
#include <iostream>
#include <unordered_map>
#include <vector>

bool i(int number) {
  for (int x = 2; x < number; x++) {
    if (number % x == 0) {
      return false;
    }
  }
  return true;
}

int main() {
  std::vector<int> primes;
  for (int x = 100; x < 1000; x++) {
    if (i(x)) {
      primes.push_back(x);
    }
  }

  std::unordered_map<std::string, int> slov;
  slov["zero"] = 0;
  slov["one"] = 1;
  slov["two"] = 2;
  slov["three"] = 3;
  slov["four"] = 4;
  slov["five"] = 5;
  slov["six"] = 6;
  slov["seven"] = 7;
  slov["eight"] = 8;
  slov["nine"] = 9;

  std::string input;
  std::getline(std::cin, input);
  std::vector<std::string> stroka;
  std::string word;
  for (char c : input) {
    if (c == ' ') {
      stroka.push_back(word);
      word.clear();
    } else {
      word += c;
    }
  }
  stroka.push_back(word);
  try {
    int line =
        slov[stroka[0]] * 100 + slov[stroka[1]] * 10 + slov[stroka[2]];
    if (line < 100 || line > 999) {
      std::cout << "wrong input" << std::endl;
    } else {
      int rast = 1000;
      int zap = 0;
      for (int elem : primes) {
        if (std::abs(elem - line) < rast) {
          rast = std::abs(elem - line);
          zap = elem;
        }
      }
      std::cout << zap << std::endl;
    }
  } catch (...) {
    std::cout << "wrong input" << std::endl;
  }

  return 0;
}